package cn.knight.service.impl;

import cn.knight.domain.Product;
import cn.knight.domain.Store;
import cn.knight.dto.ProductDto;
import cn.knight.mapper.ProductMapper;
import cn.knight.productfeign.ProductFeignClient;
import cn.knight.service.IProductServcie;
import cn.knight.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class ProductServcieImpl implements IProductServcie {

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private ProductFeignClient productFeignClient;

    @Override
    public Result save(ProductDto productDto)  {
        Product product = new Product();
        product.setName(productDto.getName())
                .setPrice(productDto.getPrice());
        productMapper.save(product);

        Store store = new Store();
        store.setProduct_id(product.getId().intValue()).
                setNumber(productDto.getNumber());
        Result result = productFeignClient.save(store);

        return  result;


    }
}
